/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.seclust;

import java.util.Arrays;
import java.util.Collections;

/**
 *
 * @author baga
 */
public class StatFunc {
    Double[] data;
    Double[] dataOrig;

    public StatFunc(Double[] dataOrig, Double[] data) {
        this.dataOrig = dataOrig;
        Arrays.sort(data, Collections.reverseOrder());
        this.data = data;
    }

    public double mean() {
        double meanResult = 0.0;
        for(Double tempData : dataOrig) {
            meanResult += tempData.doubleValue();
        }
        double res = meanResult/dataOrig.length;
//        System.out.println("avg "+res);
        return (res);
    }

    public double getSumm() {
        double temp = 0.0;
        for(int i=0; i<data.length; i++) {
            temp += data[i];
        }
        return temp;
    }

    public double stdDev() {
        double stdDevRes = 0.0;
        double mean = mean();
        for(Double tempData : dataOrig) {
            tempData = tempData - mean;
            tempData = Math.pow(tempData, 2);
            stdDevRes += tempData;
        }
        double res = Math.sqrt((stdDevRes/dataOrig.length));
        return res;

    }

    public double getQuality() {
        return data[0] - (mean() + stdDev());
    }

    public double getQuality(double edge) {
        double sum = 0.0;
        for(int i=0; i<edge; i++) {
            sum += data[i] - mean() + stdDev();
        }
        return sum;
    }

//    public static void main(String[] args) {
//        Double[] nilai = {2.0, 3.0, 4.0, 2.0, 5.0, 7.0, 11.0, 12.0};
//        StatFunc statFunc = new StatFunc(nilai);
//        System.out.println("di dapatkan rata-rata " + statFunc.mean());
//        System.out.println("Dengan standar deviasi sebesar " + statFunc.stdDev());
//    }
}
